count the number of substrings that start and end with 1

       
        
        Given a binary string S. The task is to count the number of substrings that starts and end with 1.
        Note: The starting and the ending 1s should be different. 

        Example 1:

        Input:
        S = "10101"
        Output: 3
        Explanation: The 3 substrings are "101","10101" and "101".

        Example 2:

        Input: 
        S = "100"
        Output: 0
        Explanation: No substring that starts and ends with 1
        
        
Code int countSubstr (string s) { int i,j,n; n=s.size(); int c=0; for(i=0;i<n;i++) { if(s[i]=='1') c++; } int k=c*(c-1); return k/2; }